/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.agent.execute;

import cn.ac.iie.agent.controller.Controller;
import cn.ac.iie.di.commons.httpserver.framework.handler.HandlerI;
import cn.ac.iie.di.commons.httpserver.framework.util.ParseRequestStream;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.eclipse.jetty.server.Request;

/**
 *
 * @author zhangyun
 */
public class Kill implements HandlerI {

    private static Logger logger = Logger.getLogger(Kill.class);

    /**
     *
     * @param pRequestContent
     * @return
     */
    public String execute(Request pRequest) {
        String pRequestContent = "";
        try {
            pRequestContent = ParseRequestStream.parseRequestStreamAsString(pRequest.getInputStream());
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
        
        boolean flag = false;
        Iterator<String> itr2 = Controller.subThreadList.iterator();
        while (itr2.hasNext()) {
            if (itr2.next().equals(pRequestContent)) {
                itr2.remove();
                flag = true;
                break;
            }
        }
        if (flag) {
            logger.info("name: " + pRequestContent + " remove!");
        } else {
            logger.info("name: " + pRequestContent + " don't need remove!");
        }
        Iterator<String> itr3 = Controller.subThreadList.iterator();
        while (itr3.hasNext()) {
            logger.info("runing system:" + itr3.next());
        }
        return "";
    }
}
